//
//  SZPictorialViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "SZPictorialViewController.h"
#import "SZPictorialMainViewController.h"
#import "SZFilmCriticController.h"
#import "SZCoarseCerealsController.h"
#import "SZClassicLinesController.h"
#import "HMSideMenu.h"
#import "CJPictorialCellWebViewViewController.h"
@interface SZPictorialViewController ()
/** 画报控制器 */
@property (nonatomic, strong) SZPictorialMainViewController *pictiorialMainVC;
/** 影评控制器 */
@property (nonatomic, strong) SZFilmCriticController *filmCriticVC;
/** 杂粮控制器 */
@property (nonatomic, strong) SZCoarseCerealsController *coarseCerealsVC;
/** 经典台词控制器 */
@property (nonatomic, strong) SZClassicLinesController *classicLinesVC;

/** 菜单栏 */
@property (nonatomic, strong) HMSideMenu *sideMenu;
@end

@implementation SZPictorialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

   // self.navigationController.navigationBar.translucent = NO;
   // self.tabBarController.tabBar.translucent = NO;
    // 添加控制器
    [self addAllControllerView];
    
    // 添加点击出现选择菜单Item
    [self addMenuItem];
    
    // 添加菜单按钮
    [self addMenu];
}

- (void)addMenu {
    // 添加影评菜单
    UIView *filmCriticItem = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [filmCriticItem setMenuActionWithBlock:^{
        [self.sideMenu close];
        [self.view bringSubviewToFront:_filmCriticVC.view];
        [self.view bringSubviewToFront:self.sideMenu];
    }];
    UIImageView *filmCriticIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [filmCriticIcon setImage:[UIImage imageNamed:@"filmCritic"]];
    [filmCriticItem addSubview:filmCriticIcon];
    
    // 添加画报菜单
    UIView *pictorialItem = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [pictorialItem setMenuActionWithBlock:^{
        [self.sideMenu close];
        [self.view bringSubviewToFront:_pictiorialMainVC.view];
        [self.view bringSubviewToFront:self.sideMenu];
    }];
    UIImageView *pictorialIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40 , 40)];
    [pictorialIcon setImage:[UIImage imageNamed:@"pictorial"]];
    [pictorialItem addSubview:pictorialIcon];
    
    // 添加杂粮菜单
    UIView *coarseCerealsItem = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [coarseCerealsItem setMenuActionWithBlock:^{
        [self.sideMenu close];
        [self.view bringSubviewToFront:_coarseCerealsVC.view];
        [self.view bringSubviewToFront:self.sideMenu];
    }];
    UIImageView *coarseCerealsIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [coarseCerealsIcon setImage:[UIImage imageNamed:@"coarseCereals"]];
    [coarseCerealsItem addSubview:coarseCerealsIcon];
    
    // 添加经典台词菜单
    UIView *classicLinesItem = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [classicLinesItem setMenuActionWithBlock:^{
        [self.sideMenu close];
        [self.view bringSubviewToFront:_classicLinesVC.view];
        [self.view bringSubviewToFront:self.sideMenu];
    }];
    UIImageView *classicLinesIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [classicLinesIcon setImage:[UIImage imageNamed:@"classicLines"]];
    [classicLinesItem addSubview:classicLinesIcon];
    
    
    // 将所有菜单加入菜单第三方
    self.sideMenu = [[HMSideMenu alloc] initWithItems:@[filmCriticItem, pictorialItem, coarseCerealsItem, classicLinesItem]];
    [self.sideMenu setItemSpacing:5.0f];
    [self.view addSubview:self.sideMenu];
}


/**
 *  添加控制器的view为子视图
 */
- (void)addAllControllerView {
   
    __block SZPictorialViewController *blockSelf = self;
    
    
    //影评
    _filmCriticVC = [[SZFilmCriticController alloc] init];
    _filmCriticVC.view.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kTabBarHeight - kNavigationBarHeight);
    _filmCriticVC.filmBlock = ^(NSString *tid) {
        [blockSelf pushToWebView:tid];
        
    };
    
    [self.view addSubview:_filmCriticVC.view];
    //杂粮
    _coarseCerealsVC = [[SZCoarseCerealsController alloc] init];
        _coarseCerealsVC.view.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kTabBarHeight - kNavigationBarHeight);
    _coarseCerealsVC.cocarseCerealsBlock = ^(NSString *tid) {
        [blockSelf pushToWebView:tid];
        
    };
    [self.view addSubview:_coarseCerealsVC.view];
    //经典台词
    _classicLinesVC = [[SZClassicLinesController alloc] init];
    _classicLinesVC.view.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kTabBarHeight -         kNavigationBarHeight);
    [self.view addSubview:_classicLinesVC.view];
    //画报
    _pictiorialMainVC = [[SZPictorialMainViewController alloc] init];
        _pictiorialMainVC.view.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight);

    _pictiorialMainVC.pictorialMainBlock = ^(NSString *tid) {
        [blockSelf pushToWebView:tid];
    };
    [self.view addSubview:_pictiorialMainVC.view];
}


/**
 
 跳转到WebView
 
 */

- (void)pushToWebView:(NSString *)tid {
    CJPictorialCellWebViewViewController *webViewVC = [[CJPictorialCellWebViewViewController alloc] init];
    webViewVC.tid = tid;
    [self.navigationController pushViewController:webViewVC animated:YES];
}





/**
 *  添加选择菜单item
 */
- (void)addMenuItem {
    UIImage *image = [[UIImage imageNamed:@"menu_pictorial"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(menuItemAction)];
    self.navigationItem.leftBarButtonItem = menuItem;
}

/**
 *  菜单Item点击触发
 */
- (void)menuItemAction {
    // 更改菜单栏显示/隐藏
    if (self.sideMenu.isOpen)
        [self.sideMenu close];
    else
        [self.sideMenu open];
}
@end
